﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Web;
using System.Configuration;
using System.Web.Caching;

namespace Slja.Web.Common
{
   public class XmlDoc
    {
       public static XmlDocument GetOrderListViewDoc()
       {
           return getXmlCache("CacheKey_OrderListViewDoc", "OrderListViewDoc");
       }
       public static XmlDocument getXmlCache(string key, string nodeName)
       {

           XmlDocument xml = HttpContext.Current.Cache[key] as XmlDocument;

           if (xml == null)
           {

               string xmlPath = ConfigurationManager.AppSettings[nodeName].ToString();

               xmlPath = System.Web.HttpContext.Current.Server.MapPath(xmlPath);

               xml = new XmlDocument();

               xml.Load(xmlPath);

               //缓存键依赖项。当文档内容更改时，该对象即无效，并从缓存中移除。 

               CacheDependency c = new CacheDependency(xmlPath);

               //HttpContext.Current.Cache.Insert(key, xml, c, DateTime.Now.AddSeconds(10), System.TimeSpan.Zero);

               HttpContext.Current.Cache.Insert(key, xml, c, Cache.NoAbsoluteExpiration, System.TimeSpan.Zero);
           }
           return xml;
       }


    }
}
